
//index.js
//获取应用实例
const app = getApp()
 var that={}
Page({
  data: {
    username: '',
    objectArray: ['大学物理','大学英语','高等数学','通信原理','移动网络侦查','密码学'
  ],
  index: 0,
    account:'',
    password: '',
    password1:'', 
   
    headpic:'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.17qq.com%2Fimg_qqtouxiang%2F86182920.jpeg&refer=http%3A%2F%2Fwww.17qq.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1619936649&t=9114e4476ea957f4a1db27f22fb0f991',
   
   
  },
  
  onShow: function () {
    // 生命周期函数--监听页面显示
    wx.hideTabBar({})
  },
  onLoad: function () {
    that=this;
    wx.setNavigationBarTitle({ title: '老师注册' })
  },
 //  点击组件确定事件  
 bindPickerChange: function (e) {
  console.log(e.detail.value)
   this.setData({
   index: e.detail.value
 })
},
 
  // 获取输入账号 
  usernameInput: function (e) {
    this.setData({
      username: e.detail.value
    })
  },
  userkemuInput: function (e) {
    this.setData({
      kemu: e.detail.value
    })
  },
  useraccountInput: function (e) {
    this.setData({
      account: e.detail.value
    })
  },
  
  // 获取输入密码 
  passwordInput: function (e) {
    this.setData({
      password: e.detail.value
    })
  },
   // 获取输入密码 
   passwordInput1: function (e) {
    this.setData({
      password1: e.detail.value
    })
  },


   //  点击组件确定事件  
   bindPickerChange: function (e) {
    console.log(e.detail.value)
     this.setData({
     index: e.detail.value
   })
  },
   //  点击组件确定事件  
   bindPickerChange1: function (e) {
    console.log(e.detail.value)
     this.setData({
     index1: e.detail.value
   })
  },

  bindPickerChange2: function (e) {
    console.log(e.detail.value)
     this.setData({
     index2: e.detail.value
   })
  },
  chooseImage: function () {
    
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: function (res) {
        // console.log(res)
        var tempFilePaths = res.tempFilePaths
        console.log(tempFilePaths[0])
        wx.uploadFile({
          url: app.globalData.baseUrl +'/upload',
          filePath: tempFilePaths[0],
          name: 'file',
          header: {},
          formData: {},
          success: function (res) { 
           
            console.log(res.data)
            let temp =  JSON.parse(res.data);
            var img = app.globalData.baseUrl +'/'+ temp.data;
            console.log(img);
            that.setData({
              headpic:img,
            })
          },
          fail: function (res) { },
          complete: function (res) { },
        })
       
      
     
       
      }
    })
  },
  // 注册处理
  login: function () {
    var that = this;
    if (this.data.username.length == 0 || this.data.password.length == 0|| this.data.account.length == 0) {
      wx.showToast({
        title: '姓名或密码职工号不能为空',
        icon: 'none',
        duration: 2000
      })
      return
    }
    if (this.data.password1 != this.data.password){
      wx.showToast({
        title: '两次密码不一致',
        icon: 'none',
        duration: 2000
      })
      return
    }
      wx.request({
        url: app.globalData.baseUrl +'/user/register', // 仅为示例，并非真实的接口地址
        method: 'post',
        data: {       
          pwd: that.data.password,
          name: that.data.username,
          img: that.data.headpic,
          account: that.data.account,
          type: 1,
          xueyuan: that.data.objectArray[ that.data.index] ,
          banji: that.data.kemu,
          zhuanye: that.data.kemu,
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        success(res) {
          if (res.data.code == 0) {
           
            
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000
            })
           
          } 
        }
      })
   
  }
})
